<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch"
             label-width="68px">
        <el-form-item label="单据号" prop="nos">
          <el-input v-model="queryParams.nos" placeholder="请输入单据号"
                    clearable @keyup.enter.native="handleQuery"/>
        </el-form-item>
        <el-form-item label="订单编号" prop="projectNo">
          <el-input v-model="queryParams.projectNo" placeholder="请输入订单编号"
                    clearable @keyup.enter.native="handleQuery"/>
        </el-form-item>
        <el-form-item label="产品编码" prop="code">
          <el-input v-model="queryParams.code" placeholder="请输入产品编码"
                    clearable @keyup.enter.native="handleQuery"/>
        </el-form-item>
        <el-form-item label="产品名称" prop="goodsName">
          <el-input v-model="queryParams.params['goodsName']" placeholder="请输入产品名称"
                    clearable @keyup.enter.native="handleQuery"/>
        </el-form-item>
        <el-form-item label="产品型号" prop="goodsModel">
          <el-input v-model="queryParams.params['goodsModel']" placeholder="请输入产品型号"
                    clearable @keyup.enter.native="handleQuery"/>
        </el-form-item>
        <el-form-item label="客户名称" prop="customerName">
          <el-input v-model="queryParams.customerName" placeholder="请输入客户名称"
                    clearable @keyup.enter.native="handleQuery"/>
        </el-form-item>
      <el-form-item label="制单人" prop="createBy">
        <el-input v-model="queryParams.createBy" placeholder="请输入制单人"
                  clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
        <el-form-item label="销售员" prop="saleName">
          <el-input v-model="queryParams.saleName" placeholder="请输入销售人姓名"
                    clearable @keyup.enter.native="handleQuery"/>
        </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-popconfirm title="确认入库选择的数据项？" @confirm="handlerukuAll()">
          <el-button slot="reference" type="success" plain icon="el-icon-check" size="mini" :disabled="multiple">生产批量入库
          </el-button>
        </el-popconfirm>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table border v-loading="loading" :data="dataList" @selection-change="handleSelectionChange" ref="table"
              :max-height="tableMaxHeight" @sort-change="handleSortChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column sortable label="单据号" align="center" prop="nos" />
      <el-table-column sortable label="订单编号" align="center" prop="projectNo" />
      <el-table-column sortable label="产品编码" align="center" prop="code" />
      <el-table-column sortable label="产品名称" align="center" prop="params.goodsName"/>
      <el-table-column sortable label="产品型号" align="center" prop="params.goodsModel"/>
      <el-table-column sortable label="产品数量" align="center" prop="daohuoCount" />
      <!--<el-table-column sortable label="单位" align="center" prop="unit" />-->
      <el-table-column sortable label="客户名称" align="center" prop="customerName" show-overflow-tooltip/>
      <el-table-column sortable label="销售人姓名" align="center" prop="saleName" />
      <el-table-column sortable label="生产完成时间" align="center" prop="productdate" show-overflow-tooltip/>
      <el-table-column sortable label="质检人" align="center" prop="zhijianName" />
      <el-table-column sortable label="质检时间" align="center" prop="zhijianDate" />
      <!--<el-table-column sortable label="产品类型" align="center" prop="goodsType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.goods_type" :value="scope.row.goodsType"/>
        </template>
      </el-table-column>
      <el-table-column sortable label="出入库类型" align="center" prop="type">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.churuku_type" :value="scope.row.type"/>
        </template>
      </el-table-column>
      <el-table-column sortable label="是否自制" align="center" prop="isdo">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.isdo" :value="scope.row.isdo"/>
        </template>
      </el-table-column>-->
      <el-table-column sortable label="入库状态" align="center" prop="status">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.storage_state" :value="scope.row.status"/>
        </template>
      </el-table-column>
      <el-table-column sortable label="制单人" align="center" prop="createBy" show-overflow-tooltip/>
      <el-table-column sortable label="操作工" align="center" prop="douser"show-overflow-tooltip/>
      <el-table-column sortable label="自制产品备注" align="center" prop="doremark"show-overflow-tooltip/>
      <el-table-column label="其他备注" align="center" prop="remark" show-overflow-tooltip/>
      <el-table-column label="驳回原因" align="center" prop="bohui" show-overflow-tooltip/>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button @click="modifyRemark(scope.row)" icon="el-icon-view" size="mini" type="text">
            修改备注
          </el-button>
          <el-button @click="qualityTesting(scope.row)" v-hasPermi="['develop:LvDaohuoDetail:edit']" icon="el-icon-view" size="mini" type="text">产品质检</el-button>
          <el-popconfirm title="确认入库选择的数据项？" @confirm="handleRuku(scope.row)">
            <el-button slot="reference" type="text"  icon="el-icon-check" size="mini">入库</el-button>
          </el-popconfirm>
          <el-button @click="bohui(scope.row)" icon="el-icon-view" size="mini" type="text">
            驳回
          </el-button>
          <!--<el-button size="mini" type="text" icon="el-icon-set-up"
                     @click="qualityTesting(scope.row)" v-hasPermi="['develop:LvDaohuoDetail:edit']">产品质检
          </el-button>-->
        </template>
      </el-table-column>
    </el-table>

    <factory-test-quality-goods ref="qualityTesting" @ok="getList"> </factory-test-quality-goods>
    <modifyRemark-form ref="modifyRemarkForm" @ok="getList"> </modifyRemark-form>
    <bohuiRemark-form ref="bohuiRemarkForm" @ok="getList"> </bohuiRemark-form>
    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum"
                :limit.sync="queryParams.pageSize" @pagination="getList"/>
  </div>
</template>

<script>
  import {deleteAction, getAction} from '@/api/manage'
  import FactoryTestQualityGoods from "@/views/develop/factory/factoryTestQuality/FactoryTestQualityGoods.vue";
  import ModifyRemarkForm from "@/views/develop/projectBaseInfo/module/ModifyRemarkForm";
  import BohuiRemarkForm from "@/views/develop/projectBaseInfo/module/BohuiRemarkForm";

  export default {
    name: "DairukuListFactory",
    dicts: ['isdo','goods_type','churuku_type','storage_state'],
    components: {
      FactoryTestQualityGoods,
      ModifyRemarkForm,
      BohuiRemarkForm,
    },
    data() {
      return {
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 采购单表格数据
        dataList: [],
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          params:{},
          nos: null,
          projectId: null,
          projectNo: null,
          code: null,
          customerName: null,
          saleName: null,
          createBy: null,
          status: "0",
          isdo: "1",
          type: "0",
          isZhijian: "1",
          orderByColumn: "create_time",
          isAsc: "desc",
        },
        url: {
          list: '/lvRukumingxi/lvRukumingxi/list',
          ruku: '/lvRukumingxi/lvRukumingxi/ruku/',
        },
        tableMaxHeight: window.innerHeight - 320,
      };
    },
    created() {
      this.getList();
      window.addEventListener('resize', this.getTableHeight);
    },
    destroyed() {
      window.removeEventListener('resize', this.getTableHeight)
    },
    methods: {
      bohui(row){
        this.$refs.bohuiRemarkForm.show(row);
      },
      /** 查询采购单列表 */
      getList() {
        this.loading = true;
        getAction(this.url.list, this.queryParams).then(response => {
          this.dataList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      getTableHeight() {
        this.tableHeight = window.innerHeight - 320
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
       /** 排序触发事件 */
      handleSortChange(column, prop, order) {
        this.queryParams.orderByColumn = column.prop;
        this.queryParams.isAsc = column.order;
        this.handleQuery();
      },
      /** 重置按钮操作 */
      resetQuery() {
          this.resetForm("queryForm");
          this.handleQuery();

      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id)
        this.single = selection.length !== 1
        this.multiple = !selection.length
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.$refs.form.handleUpdate(row);
      },
      /** 入库按钮操作 */
      handleRuku(row) {
        const ids = row.id || this.ids;
        getAction(this.url.ruku+ids, {}).then(response => {
          this.getList();
          this.$modal.msgSuccess("入库成功！");
        }).catch(() => {
        });
      },
      modifyRemark(row){
        this.$refs.modifyRemarkForm.show(row);
      },
      handlerukuAll() {
        const ids = this.ids;
        getAction(this.url.ruku+ids, {}).then(response => {
          this.getList();
          this.$modal.msgSuccess("入库成功！");
        }).catch(() => {
        });
      },

      qualityTesting(row){
        this.$refs.qualityTesting.showByRukuDetail(row);
      }

    }
  };
</script>
